package com.bah.tract.client.ui;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.JTable;

import com.google.inject.Inject;
import com.google.inject.Singleton;

@Singleton
public class TimeCardMouseListener extends MouseAdapter {

	private final TaskEditDialog editComponent;

	@Inject
	public TimeCardMouseListener(final TaskEditDialog component) {
		editComponent = component;
	}

	@Override
	public final void mouseClicked(final MouseEvent e) {

		if ((MouseEvent.BUTTON1 == e.getButton()) && (e.getClickCount() == 2)
				&& !e.isConsumed()) {
			e.consume();
			final JTable table = (JTable) e.getComponent();
			final TimeCardTableModel model = (TimeCardTableModel) table
					.getModel();
			final TimeCardRow row = model.getRow(table.getSelectedRow());
			editComponent.edit(row.getWork());
		}

	}
}
